_realname=openfa
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=20231011.0.2
pkgrel=1
pkgdesc='openfa is a set of algorithms and procedures that implement standard models used in fundamental astronomy (mingw-w64)'
url='https://gitlab.obspm.fr/imcce_openfa/openfa'
license=('spdx:BSD-3-Clause')
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
)
source=("https://gitlab.obspm.fr/imcce_openfa/openfa/-/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('e6c5c22742d5d1257a398133a1ff9b8815f0cb35e2cab07ecfd42668e562ecc8')

build() {
 
  declare -a extra_config

  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}"

}

check() {
  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}" --target test
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
